<template>
    <div class="header-wrapper">
        <div class="logo-box">国泰网信</div>
        <div class="center-box">
            <slot name="centerContent"></slot>
        </div>
        <div class="right-box">
            <a-button type="primary" @click="clickToggleLayout"
                >切换布局</a-button
            >
            <a-button type="primary" class="theme-btn" @click="clickToggleTheme"
                >切换皮肤</a-button
            >
            <a-popconfirm
                title="确定退出吗？"
                @confirm="clickLogout"
                ok-text="确定"
                cancel-text="取消"
            >
                <a-button type="danger">退出</a-button>
            </a-popconfirm>
        </div>
    </div>
</template>

<script>
import router, { resetRouter } from "@/router";
import store from "@/store";
export default {
    name: "headerComponent",
    components: {},
    mounted() {},
    data() {
        return {};
    },
    methods: {
        clickToggleLayout() {
            const { menuMode } = store.state.layout;
            console.log(menuMode, "menuMode");
            if (menuMode === "inline") {
                store.commit("SET_MENU_MODE", "horizontal");
            } else {
                store.commit("SET_MENU_MODE", "inline");
            }
        },
        clickToggleTheme() {
            const { theme } = store.state.layout;
            let currentTheme = "";
            if (theme === "dark") {
                currentTheme = "light";
            } else if (theme === "light") {
                currentTheme = "orange";
            } else {
                currentTheme = "dark";
            }
            store.commit("SET_THEME", currentTheme);
            document.documentElement.setAttribute("data-theme", currentTheme);
        },
        clickLogout() {
            store.commit("RESET_VUEX");
            localStorage.removeItem("ACCESS_TOKEN");
            //   localStorage中只要有IS_RELOAD，就代表未登录进系统，凡是进入系统后本地一律无IS_RELOAD
            localStorage.setItem("IS_RELOAD", "pageReload");
            document.documentElement.setAttribute("data-theme", "dark");
            this.$router.push({
                name: "login",
            });
            resetRouter();
        },
    },
};
</script>

<style lang="less" scoped>
.header-wrapper {
    display: flex;
    .logo-box {
        width: 201px;
        height: 64px;
        font-size: 24px;
        color: #fff;
    }
    .center-box {
        flex: 1;
        display: flex;
        align-items: center;
    }
    .right-box {
        margin-left: auto;
        .theme-btn {
            margin: 0 20px;
        }
    }
}
</style>
<style lang="less">
.ant-popover-buttons {
    display: flex;
}
</style>
